package com.tudouji.project.harvest.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.flow.service.pojo.BasePojo;
import com.flow.service.pojo.flow.FlowTempNode;
import com.flow.service.pojo.result.FlowResult;
import com.tudouji.framework.aspectj.lang.annotation.Excel;
import com.tudouji.project.flow.domain.Flowtempnode;
import com.tudouji.project.quality.domain.Qaitems;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 货运单对象 freightorder
 *
 * @author wf
 * @date 2021-01-18
 */
@Data
@Slf4j
public class Freightorder extends BasePojo {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    private String guid;

    /**
     * 货运单(同物流平台订单编号)
     */
    @Excel(name = "编号")
    private String code;

    @Excel(name = "采收组织名称")
    private String orgName;

    @Excel(name = "采收类型 1-商品薯采收 2 淀粉薯采收  来源于采收合同")
    private Integer type;

    private String typeName;

    @Excel(name = "入库库房")
    private String storeroom;

    private String ordercode;
    private BigDecimal deductRateByHand;
    private BigDecimal deductRateByCheck;

    /**
     * 种植户id
     */
    @Excel(name = "客户名称")
    private String plantor;

    /**
     * 品种
     */
    @Excel(name = "品种")
    private String variety;

    /**
     * 规格
     */
    @Excel(name = "规格")
    private String specification;

    /**
     * 入库过磅重量
     */
    @Excel(name = "毛重")
    private BigDecimal hweight;

    @Excel(name = "结算单价")
    private BigDecimal actualSettl;

    /**
     * 结算金额
     */
    @Excel(name = "结算金额")
    private BigDecimal settlement;

    @Excel(name = "状态")
    private String statusName;

    @Excel(name = "付款方式")
    private String paytype;

    @Excel(name = "支付状态")
    private String paystatusName;

    @Excel(name = "采收负责人")
    private String operator;

    @Excel(name = "采收日期", width = 30, dateFormat = "yyyy-MM-dd", type = Excel.Type.EXPORT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createtime;

    @Excel(name = "采收类型", readConverterExp = "1=订单户,2=临采")
    private Integer harvestType;

    /**
     * 司机姓名
     */
    @Excel(name = "司机姓名")
    private String drivername;

    /**
     * 司机电话
     */
    @Excel(name = "司机电话")
    private String driverphone;

    /**
     * 车牌号
     */
    @Excel(name = "车牌号")
    private String carcode;

    private String cartype;

    /**
     * $column.columnComment
     */
    private Long id;

    /**
     * 种植户id
     */
    private String plantorid;


    /**
     * 种植户电话(冗余)
     */
    private String plantorphone;


    /**
     * 省份
     */
    private String provence;

    /**
     * 市
     */
    private String city;

    /**
     * 区县
     */
    private String country;

    /**
     * 街道(详细)
     */
    private String street;


    /**
     * 载重(吨)
     */
    private BigDecimal amount;

    /**
     * 地块id
     */
    private String arealandid;

    /**
     * 地块名称(冗余)
     */
    private String arealand;


    /**
     * 品种id
     */
    private String productinfoid;

    /**
     * 重量(吨)
     */
    private BigDecimal weight;

    /**
     * 单价(元/吨)
     */
    private BigDecimal price;

    private BigDecimal unitPrice;

    /**
     * 采收方式:1:地头直销,2:采收入库(扫码)
     */
    private String harvest;

    /**
     * 仓库名(冗余)
     */
    private String storehouse;

    /**
     * $column.columnComment
     */
    private Integer status;

    /**
     * 操作人id
     */
    private String operatorid;
    private String keywords;

    /**
     * 最后修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date lastupdate;

    /**
     * 卸货时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date unloadtime;

    /**
     * 质检方式
     */
    private String qatype;


    /**
     * 规格id
     */
    private String specificationid;

    /**
     * 扣杂率
     */
    private BigDecimal discountrate;

    /**
     * 合同约定杂土比率
     */
    private BigDecimal soilchkrate;

    /**
     * 合同约定缺陷比率
     */
    private BigDecimal unqualifiedchkrate;

    /**
     * 1-统一扣杂法 2-杂缺分离
     */
//    private Integer deducttype;

    /**
     * 付款方式1地头付款、2验收付 生成货运单时候从 合同中读取
     */
    private String setlwgtype;

    /**
     * 合同id
     */
    private String contractid;


    /**
     * 采收公司id(组织id)
     */
    private String organizationid;

    /**
     * 支付状态：1.初始2.待申请3.已申请4.已支付
     */
    private Integer paystatus;

    /**
     * 拉货过磅重量
     */
    private BigDecimal rweight;

    /**
     * 每包装箱重量
     */
    private BigDecimal wghtperpkg;

    /**
     * 扣杂前金额
     */
    private BigDecimal unprocdAmount;

    /**
     * 扣杂标准，1-合同，2-质检单 3-就高
     */
    private Integer isdiscount;

    /**
     * 拉货纬度
     */
    private String latitude;

    /**
     * 拉货经度
     */
    private String longitude;

    /**
     * 当前扫码位置与地块距离
     */
    private String distance;

    /**
     * 产品规格id
     */
    private String spguid;

    /**
     * 部门id
     */
    private String departid;

    /**
     * 部门名字
     */
    private String department;

    /**
     * 流程id
     */
//    private String flowId;

    /**
     * 库房id
     */
    private String strguid;

    private Long strid;

    /**
     * 最终扣杂率
     */
    private BigDecimal ratend;

    private String remark;

    private String search;

    private String qaname;
    private String[] guids;

    private String address;

    private Integer userType;

    private String plantID;
    private String payCarNum;
    private String unpaidPayCarNum;
    private String payMoney;
    private String unpaidMoney;
    private String dictkey;
    private String sumCarNum;
    private BigDecimal unpaidWeight;

    private String unpaidSettlement;

    private String unpaidCount;

    private Integer[] stats;

    private Integer[] nostats;
    private Integer[] paystats;

    private Integer flag;//权限:1有,2无

    private Integer bang;//过磅权限

    private Integer aqflag;//质检权限

    private Integer scan;//扫码卸货

    private Integer schedul;//直销调度权限

    private Acceptform acceptform;

    private BigDecimal deductrate;//扣杂率

    private BigDecimal damount;//扣杂前金额

    private String statusname;//状态名称

    private Integer count;//数量

    private String[] statusArr;

    private BigDecimal unprocd_amount;

    private String fromsrguid;

    private String condition;

    private String qamainid;

//    private String deducttypeName;
    private String isdiscountName;
    private String[] departids;

    private String[] strguids;

    private List<FlowTempNode> nodes;

    //验收状态:0-初始 1-合格 2-不合格 3 拒收
    private Integer acceptStatus;
    /**
     * 拒绝标识:1-正常，2-拒绝
     */
    private Integer refuseFlag;

    private String telphone;
    private String realName;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date insrstartdate;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date insrenddate;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date startdate;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date enddate;

    private Integer[] payStatusList;
    private Integer[] statusList;
    private String[] storeroomeIdList;
    private String[] departidList;

    @Excel(name = "净重")
    private BigDecimal netWeight;

    private BigDecimal pkgwgh;
    private String supplierName;
    private Long supplierId;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date whinTime;

    private List<Qaitems> qaitems;

    private String sthguid;
    private Integer num;

    private Integer sellformPayType;
    private Long sellformId;
    private String sellformCode;

    private String harvestName;
    private String sellformPayTypeName;

    /** 价格确认方式1.入库前确认2.入库后确认 */
    private Integer priceMethod;
    private String priceMethodName;
    /** 确认单价 */
    private  BigDecimal confirmedPrice;

    @Override
    public void prepareForProcess(){
        log.info("set values for flow process in fo vo:");
        setBusTable("freightorder");
        setPlatformId(getStrid());
        setToPlatformId(getStrid());
    }
    @Override
    public boolean backToStartNode(FlowResult result){
        if (getPaystatus().intValue()>2){
            result.setMsg("已发起付款申请，不能退回到发起");
            return false;
        }
        return  true;
    }
    @Override
    public String getCondition() {
        return condition;
    }

    @Override
    public void setCondition(String condition) {
        this.condition = condition;
    }

    @Override
    public String getValueByParam(String param) {
        try {
            Field field = this.getClass().getDeclaredField(param);
            // 设置对象的访问权限，保证对private的属性的访问
            field.setAccessible(true);
            return field.get(this) == null ? "" : field.get(this).toString();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("guid", getGuid())
                .append("code", getCode())
                .append("plantorid", getPlantorid())
                .append("plantor", getPlantor())
                .append("plantorphone", getPlantorphone())
                .append("drivername", getDrivername())
                .append("driverphone", getDriverphone())
                .append("provence", getProvence())
                .append("city", getCity())
                .append("country", getCountry())
                .append("street", getStreet())
                .append("carcode", getCarcode())
                .append("amount", getAmount())
                .append("arealandid", getArealandid())
                .append("arealand", getArealand())
                .append("variety", getVariety())
                .append("productinfoid", getProductinfoid())
                .append("weight", getWeight())
                .append("price", getPrice())
                .append("settlement", getSettlement())
                .append("harvest", getHarvest())
                .append("storeroom", getStoreroom())
                .append("storehouse", getStorehouse())
                .append("createtime", getCreatetime())
                .append("status", getStatus())
                .append("operatorid", getOperatorid())
                .append("lastupdate", getLastupdate())
                .append("remark", getRemark())
                .append("unloadtime", getUnloadtime())
                .append("qatype", getQatype())
                .append("specification", getSpecification())
                .append("specificationid", getSpecificationid())
                .append("discountrate", getDiscountrate())
                .append("soilchkrate", getSoilchkrate())
                .append("unqualifiedchkrate", getUnqualifiedchkrate())
                .append("setlwgtype", getSetlwgtype())
                .append("contractid", getContractid())
                .append("hweight", getHweight())
                .append("organizationid", getOrganizationid())
                .append("paystatus", getPaystatus())
                .append("rweight", getRweight())
                .append("wghtperpkg", getWghtperpkg())
                .append("unprocdAmount", getUnprocdAmount())
                .append("isdiscount", getIsdiscount())
                .append("latitude", getLatitude())
                .append("longitude", getLongitude())
                .append("distance", getDistance())
                .append("spguid", getSpguid())
                .append("departid", getDepartid())
                .append("department", getDepartment())
                .append("flowid", getFlowId())
                .append("strguid", getStrguid())
                .append("operator", getOperator())
                .append("ratend", getRatend())
                .toString();
    }
}
